package newPutFormat;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class NewOutputFormatDriver {
    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        conf.set("fs.defaultFS", "hdfs://192.168.0.155:9000");
        Job job = Job.getInstance(conf);

        job.setMapperClass(NewOutputFormatMapper.class);
        job.setReducerClass(NewOutputFormatReduce.class);
        job.setJarByClass(NewOutputFormatDriver.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(DoubleWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(DoubleWritable.class);

        job.setOutputFormatClass(NewOutputFormat.class);

        Path path = new Path("file:///home/data/mapreduce/data_out/output");
        if (path.getFileSystem(conf).exists(path)) {
            path.getFileSystem(conf).delete(path, true);
        }

        FileInputFormat.setInputPaths(job, "file:///home/data/mapreduce/data_out/input");
        FileOutputFormat.setOutputPath(job, new Path("file:///home/data/mapreduce/data_out/output"));

        boolean b = job.waitForCompletion(true);
        System.exit(b ? 0 : 1);
    }
}
